var studentService = require('../service/studentService')
const JWT = require('../util/JWT')

module.exports = {
    async login(req, res) {
        var result = await studentService.login(req.body)
        if (result) {
            let { _id, studentname, gender, introduction, avatarUrl } = result
            const data = { _id, username: studentname }
            res.header('Authorization', JWT.generate(data, '1800s'))

            res.send({
                status: "success",
                data: {
                    ...data,
                    gender,
                    introduction,
                    avatarUrl,
                    role: {
                        "id": 1,
                        "roleName": "学生",
                        "roleType": 3,
                        "rights": [
                            "/index",
                            "/center",
                            "/interview-manage",
                            "/interview-manage/companylist",
                            "/interview-manage/companydata",
                            "/student-manage",
                            "/student-manage/studentlist",
                        ]
                    },
                }
            })
        } else {
            res.status(401).send({
                status: "用户名或密码错误",
            })
        }
    },
    async addList(req, res) {
        var result = await studentService.addList(req.body)
        res.send(result)
    },
    async getList(req, res) {
        var result = await studentService.getList()
        res.send(result)
    },
    async update(req, res) {
        var result = await studentService.update(req.params.id, req.body)
        res.send(result)
    },
    async delete(req, res) {
        var result = await studentService.delete(req.body)
        res.send(result)
    }
}